package com.kdtech.analyse.video;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.kdtech.crawler.CrawlHTML;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.StringUtils;
import com.kdtech.analyse.AnalyseNews;

/**
 * 东营网络电视台
 * @author Persh
 */
public class HhekAnalyse implements AnalyseNews{



	
	public boolean isDetailPage(String url) {
		boolean bRet = false;
		String[] regex = {
				"http://www.hhek.cn/video/[0-9]{4}-[0-9]{2}/[0-9]{2}/.*.shtml",
				"http://www.hhek.cn/.*/[0-9]{4}-[0-9]{2}/[0-9]{2}/cms[0-9]+article.shtml",
				"http://www.hhek.cn/news/[0-9]{4}-[0-9]{2}/[0-9]{2}/cms[0-9]+article.shtml",
				};

		for (int i = 0; i < regex.length; i++) {
			if (url.matches(regex[i])) {
				return true;
			}
		}
		return bRet;
	}

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {
		NewsMeta video = new NewsMeta();
		if (urlMeta.getHtml() == null) {
		}
		String htmltxt = urlMeta.getHtml();
		String url = urlMeta.getUrl();
		if(!isDetailPage(url)){
		}
		video.setUrl(url);
		String title = null;
		String desc = null;
		Long date = null;
		String content = null;
		Document doc = Jsoup.parse(htmltxt);

		title = doc.select(".news_tit").text();
     	desc = doc.select("div#cms_content_div").text();
		date = DateUtils.matchDate(doc.select(".news_fb_time").text());
		video.setTitle(StringUtils.trimSpace(title));
		video.setContent(desc);
		video.setDate(date);

		return video;
	}
	

	
	public NewsMeta Update(NewsMeta meta) {
		return null;
	}

	
}
